// https://echarts.apache.org/examples/zh/editor.html?c=area-basic 代碼測試地址


import * as echarts from 'echarts';

var chartDom = document.getElementById('main');
var myChart = echarts.init(chartDom);
var option;

data = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
sdata = [
  820, 932, 901, 934, 1290, 1330, 1320, 820, 932, 901, 934, 1290, 1330, 1320,
  820, 932, 901, 934, 1290, 1330, 1320
];
count = 0;
span = 4;
len = Math.ceil(data.length / span);

function test() {
  if (count == 3) {
    count = 0;
  }
  option = {
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: data.filter(
        (item, index) => index >= count * span && index < (count + 1) * span
      )
    },
    yAxis: {
      type: 'value'
    },
    series: [
      {
        data: sdata.filter(
          (item, index) => index >= count * span && index < (count + 1) * span
        ),
        type: 'line',
        areaStyle: {}
      }
    ]
  };
  option && myChart.setOption(option);
  count++;

  setTimeout(function () {
    test();
  }, 3000);
}
test();

option && myChart.setOption(option);

// 定時修改echarts數據